module Tomahawk
  module DirectiveGroups
    class Base
      attr_accessor :parameters, :directives, :groups

      def initialize(parameters = '', directives = {}, groups = [])
        yield(directives, groups) if block_given?
        @parameters = parameters
        @directives = Hash[directives]
        @groups = Array(groups)
      end

      def to_str
        raise "#{self.class.name} doesn't support #conf!"
      end

      def to_s
        to_str
      end

      def ==(obj)
        self.class == self.class && self.parameters == obj.parameters && self.directives == obj.directives && self.groups == obj.groups
      rescue
        false
      end

      def name
        self.class.name.split('::').last
      end
    end
  end
end
